// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   CMIObjectiveData.java

package com.iphaeton.lms.course.scorm12.datamodel.cmi;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import com.iphaeton.lms.course.scorm12.datamodel.Element;
import java.io.PrintStream;
import java.io.Serializable;

// Referenced classes of package com.iphaeton.lms.course.scorm12.datamodel.cmi:
//            CMICategory, CMIScore, CMIRequest, DMErrorManager

public class CMIObjectiveData extends CMICategory
    implements Serializable
{

    public CMIObjectiveData()
    {
        super(true);
        id = new Element("", "checkIdentifier", "NULL", true, true, false);
        score = new CMIScore();
        status = new Element("", "checkVocabulary", "Status", true, true, false);
    }

    public Element getStatus()
    {
        return status;
    }

    public CMIScore getScore()
    {
        return score;
    }

    public Element getId()
    {
        return id;
    }

    public void setStatus(String inStatus)
    {
        status.setValue(inStatus);
    }

    public void setScore(CMIScore inScore)
    {
        score.getRaw().setValue(inScore.getRaw().getValue());
        score.getMin().setValue(inScore.getMin().getValue());
        score.getMax().setValue(inScore.getMax().getValue());
    }

    public void setId(String inID)
    {
        id.setValue(inID);
    }

    public boolean isInitialized()
    {
        return initialized;
    }

    public String performGet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        String result = new String("");
        if(isValidObjectiveDataRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            if(theRequest.hasMoreTokensToProcess())
                result = processSubcategory(theRequest, token, dmErrorMgr);
            else
            if(theRequest.isAChildrenRequest())
                result = getChildren();
            else
                result = determineElementValue(this, token, dmErrorMgr);
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Request being processed: " + theRequest.getRequest() + "\nis not a valid request for the CMI Objective\n" + "Data Model Category");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
        return result;
    }

    public String getChildren()
    {
        String children = "id,status,score";
        return children;
    }

    public void performSet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        if(isValidObjectiveDataRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            String result;
            if(theRequest.hasMoreTokensToProcess())
            {
                result = processSubcategory(theRequest, token, dmErrorMgr);
            } else
            {
                String value = theRequest.getValue();
                if(theRequest.isAKeywordRequest())
                {
                    dmErrorMgr.recKeyWordError(token);
                } else
                {
                    doSet(this, token, value, dmErrorMgr);
                    initialized = true;
                }
            }
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Request being processed: " + theRequest.getRequest() + "\nis not a valid request for the CMI Objective\n" + "Data Model Category");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
    }

    private String processSubcategory(CMIRequest theRequest, String theElement, DMErrorManager dmErrorMgr)
    {
        if(_Debug)
        {
            System.out.println("In CMIObjectiveData::processSubcategory()");
            System.out.println("The Element: " + theElement);
        }
        String result = new String("");
        try
        {
            java.lang.reflect.Field tmpField = getClass().getField(theElement);
            if(theRequest.isForASetRequest())
            {
                if(theRequest.isAKeywordRequest())
                    dmErrorMgr.recKeyWordError(theRequest.getElement());
                else
                    score.performSet(theRequest, dmErrorMgr);
            } else
            if(theElement.equals("score"))
                result = score.performGet(theRequest, dmErrorMgr);
            else
            if(theRequest.isAKeywordRequest())
                dmErrorMgr.recGetKeyWordError(theRequest.getElement());
            else
                dmErrorMgr.recNotImplementedError(theRequest);
        }
        catch(NoSuchFieldException nsfe)
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Element being processed: " + theElement + "is not a valid sub category of the CMI " + "Objectives\nData Model Category");
            }
            dmErrorMgr.SetCurrentErrorCode("401");
        }
        catch(SecurityException se)
        {
            if(_Debug)
            {
                System.out.println(se);
                System.out.println("Access to the information is denied");
            }
            dmErrorMgr.SetCurrentErrorCode("101");
        }
        return result;
    }

    private boolean isValidObjectiveDataRequest(CMIRequest theRequest)
    {
        boolean rtrnFlag = false;
        if(theRequest.getTotalNumTokens() >= CMIOBJECTIVEDATA_MIN_NUM_TOKENS)
            rtrnFlag = true;
        return rtrnFlag;
    }

    public String isValidRequest(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        boolean flag = false;
        String result = new String("");
        if(theRequest.getTotalNumTokens() <= 5)
        {
            String token = theRequest.getNextToken();
            if(_Debug)
                System.out.println("token: " + token);
            if(token.equals("id") || token.equals("status"))
            {
                if(theRequest.hasMoreTokensToProcess())
                {
                    flag = false;
                    dmErrorMgr.recNotImplementedError(theRequest);
                } else
                {
                    dmErrorMgr.SetCurrentErrorCode("0");
                }
            } else
            if(token.equals("score"))
            {
                flag = score.isValidRequest(theRequest);
                if(theRequest.isAChildrenRequest())
                    result = score.getChildren();
            }
        } else
        {
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        return result;
    }

    public void showData()
    {
        if(_Debug)
        {
            System.out.println("CMI Objective Data Object:");
            System.out.println("\tid: " + getId().getValue());
            System.out.println("\tstatus: " + getStatus().getValue());
            System.out.println("\tscore.raw: " + getScore().getRaw().getValue());
            System.out.println("\tscore.min: " + getScore().getMin().getValue());
            System.out.println("\tscore.max: " + getScore().getMax().getValue());
        }
    }

    private static final long serialVersionUID = 0x51434d44e3c7bf46L;
    private static boolean _Debug;
    public Element id;
    public CMIScore score;
    public Element status;
    private boolean initialized;
    static int CMIOBJECTIVEDATA_MIN_NUM_TOKENS = 3;

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
